
React = require('react')
{connect} = require('react-redux')
{View,Animated,Easing,NetInfo,StatusBar,Text,Image,StyleSheet,ScrollView,TouchableOpacity,AsyncStorage} = require('react-native')
Flex = require('antd-mobile/lib/flex')
Button = require('antd-mobile/lib/button')
Icon = require('antd-mobile/lib/icon')
Drawer = require('antd-mobile/lib/drawer')
DrawerLayout = require('react-native-drawer-layout')
List = require('antd-mobile/lib/list')
Item = List.Item
Brief = Item.Brief
{ width, height } = require('../utilities/getScreen.js')
backImg = require('../img/forward.png')
menuImg = require('../img/menu.png')
DrawerMenu = React.createClass
  getInitialState:->
    menuIsOpen : false
    rotation: new Animated.Value(0)

  runAnimate:(isOpen)->
    if isOpen isnt @state.menuIsOpen
      that = @
      value = if isOpen then -1 else 1
      @setState menuIsOpen:isOpen,->
        Animated.timing(@state.rotation,
          toValue:value
          duration: 300
          easing: Easing.linear).start ->
            that.setState rotation: new Animated.Value(0)
  drawerClickHandle:->
    if @state.menuIsOpen
      @props.closeDrawer()
    else
      @props.openDrawer()
    @runAnimate(!@state.menuIsOpen)
  render:->
    <View style={{flexDirection:'row',marginTop:10,flex:0,alignItems:'center',width:width,height:40}}>
      <TouchableOpacity onPress={@drawerClickHandle}>
          <Animated.Image ref='menuIcon' source={if @state.menuIsOpen then backImg else menuImg}  style={{
            marginLeft:10
            width:width / 12
            height:width / 12
            resizeMode:'contain'
            transform:
              [{
                rotateZ: @state.rotation.interpolate({
                    inputRange: [0,1],
                    outputRange: ['0deg', '180deg']})
              }]
            }}/>
      </TouchableOpacity>
      <Text style={{fontSize:24,color:'#FFFFFF',flex:1,textAlign:'center'}}>台州港引航站</Text>
      <View style={{width:width / 12,marginRight:10}}></View>
    </View>

module.exports = DrawerMenu
